﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
//new
using System.Drawing;
using System.IO;
using DataInterfaceDLL;

namespace JKZP
{
    public abstract class JKCamera
    {
        public string m_RoadID;
        public string m_RoadName;
        public string m_GBDM;
        public string m_BMBH;
        public string m_CameraName;
        public PP.CAMERAPOSITION m_Position;
        public PP.JKCAMERATYPE m_Type;
        public string m_IP;
        public int m_Port;
        public string m_UserName;
        public string m_PassWord;
        public int m_LoginID;
        public int m_Channel;
        public bool m_CamIsOpen;
        public int m_PlayHandle;
        public DateTime m_WFSJ;
        public string m_HPHM;
        public string m_WFXWDM;
        public string m_ManuelHPZL;
        public string m_CDMC;
        public string m_CDDM;
        public string m_SnapCount;
        public string m_TempPicName;
        public List<string> m_PreSetPonitHelpName;
        public string m_bz;
        public string m_FileName1;
        public string m_FileName2;
        public string m_FileName3;
        public string m_deviceID;

        public abstract void Init();
        public abstract void Login();
        public abstract void StartPreView(IntPtr handle);
        public abstract bool CaptureOnePic(string group,string index);
        public abstract bool SaveOneGroup(string group);
        public abstract void StopPreView();
        public abstract void Logout();
        public abstract void Left(int speed,bool stop);
        public abstract void Right(int speed, bool stop);
        public abstract void Up(int speed, bool stop);
        public abstract void Down(int speed, bool stop);
        public abstract void ZoomIn(int speed, bool stop);
        public abstract void ZoomOut(int speed, bool stop);
        public abstract void Yushua(int speed, bool stop);
        public abstract void PTZ3D(Rectangle WinRect,Point pointStart,Point pointEnd);
        public abstract void CallPreSetPoint(int index);
        public abstract bool SavePreSetPoint(int index);
        public abstract void ShutDown();
        public abstract void CheckTime();
        public abstract void Play(IntPtr handle);
        public abstract void FindFile(DateTime from, DateTime to);
        public abstract void StartPlayVideo(int index);
        public abstract void StopPlayVideo(int index);
        public abstract void PausePlayVideo(int index);
        public abstract void FowardPlayVideo(int index);
        public abstract void BackPlayVideo(int index);
        public abstract DateTime GetDeviceTime();
        public string MakeSubFolder(List<string> subFolderType)
        {
            string ans = "";
            string splitor = "\\";
            try
            {
                if (subFolderType != null)
                {
                    for (int i = 0; i < subFolderType.Count; i++)
                    {
                        PP.FOLDERSAVEMODE mode = (PP.FOLDERSAVEMODE)Enum.Parse(typeof(PP.FOLDERSAVEMODE), subFolderType[i]);
                        switch (mode)
                        {
                            case PP.FOLDERSAVEMODE.按方向保存:
                                ans += (splitor + m_Position.ToString());
                                break;
                            case PP.FOLDERSAVEMODE.按路口代码保存:
                                ans += (splitor + m_RoadID);
                                break;
                            case PP.FOLDERSAVEMODE.按路口名称保存:
                                ans += (splitor + m_RoadName);
                                break;
                            case PP.FOLDERSAVEMODE.按年保存:
                                ans += (splitor + m_WFSJ.ToString("yyyy"));
                                break;
                            case PP.FOLDERSAVEMODE.按年月日保存:
                                ans += (splitor + m_WFSJ.ToString("yyyyMMdd"));
                                break;
                            case PP.FOLDERSAVEMODE.按日保存:
                                ans += (splitor + m_WFSJ.ToString("dd"));
                                break;
                            case PP.FOLDERSAVEMODE.按摄像机IP保存:
                                ans += (splitor + m_IP);
                                break;
                            case PP.FOLDERSAVEMODE.按摄像机类型保存:
                                ans += (splitor + m_Type.ToString());
                                break;
                            case PP.FOLDERSAVEMODE.按月保存:
                                ans += (splitor + m_WFSJ.ToString("MM"));
                                break;
                            case PP.FOLDERSAVEMODE.按摄像机名称保存:
                                ans += (splitor + m_CameraName);
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            catch
            {
                ans = "";
            }
            return ans;
        }
        public string MakePicName(string snapindex,List<string> picNameType, List<string> picNameText)
        {
            string ans = "";
            try
            {
                if ((picNameType != null) && (picNameText != null))
                {
                    for (int i = 0; i < picNameType.Count; i++)
                    {
                        PP.PICNAMEMODE mode = (PP.PICNAMEMODE)Enum.Parse(typeof(PP.PICNAMEMODE), picNameType[i]);
                        switch (mode)
                        {
                            case PP.PICNAMEMODE.指定字符:
                                ans += picNameText[i];
                                break;
                            case PP.PICNAMEMODE.车道代码:
                                ans += m_CDDM;
                                break;
                            case PP.PICNAMEMODE.车道名称:
                                ans += m_CDMC;
                                break;
                            case PP.PICNAMEMODE.车牌号码:
                                ans += m_HPHM;
                                break;
                            case PP.PICNAMEMODE.分:
                                ans += m_WFSJ.ToString("mm");
                                break;
                            case PP.PICNAMEMODE.毫秒:
                                ans += m_WFSJ.ToString("fff");
                                break;
                            case PP.PICNAMEMODE.路口代码:
                                ans += m_RoadID;
                                break;
                            case PP.PICNAMEMODE.路口名称:
                                ans += m_RoadName;
                                break;
                            case PP.PICNAMEMODE.秒:
                                ans += m_WFSJ.ToString("ss");
                                break;
                            case PP.PICNAMEMODE.年:
                                ans += m_WFSJ.ToString("yyyy");
                                break;
                            case PP.PICNAMEMODE.日:
                                ans += m_WFSJ.ToString("dd");
                                break;
                            case PP.PICNAMEMODE.摄像机IP:
                                ans += m_IP;
                                break;
                            case PP.PICNAMEMODE.方向名称:
                                ans += m_Position.ToString();
                                break;
                            case PP.PICNAMEMODE.方向代码:
                                switch (m_Position)
                                {
                                    case PP.CAMERAPOSITION.东:
                                        ans += "1";
                                        break;
                                    case PP.CAMERAPOSITION.南:
                                        ans += "2";
                                        break;
                                    case PP.CAMERAPOSITION.西:
                                        ans += "3";
                                        break;
                                    case PP.CAMERAPOSITION.北:
                                        ans += "4";
                                        break;
                                    default:
                                        break;
                                }

                                break;
                            case PP.PICNAMEMODE.摄像机类型:
                                ans += m_Type.ToString();
                                break;
                            case PP.PICNAMEMODE.时:
                                ans += m_WFSJ.ToString("HH");
                                break;
                            case PP.PICNAMEMODE.图片格式:
                                ans += ".jpg";
                                break;
                            case PP.PICNAMEMODE.月:
                                ans += m_WFSJ.ToString("MM");
                                break;
                            case PP.PICNAMEMODE.抓拍张数:
                                ans += m_SnapCount;
                                break;
                            case PP.PICNAMEMODE.连拍序号:
                                ans += snapindex;
                                break;
                            case PP.PICNAMEMODE.国标代码:
                                ans += m_GBDM;
                                break;
                            case PP.PICNAMEMODE.违法行为代码:
                                ans += m_WFXWDM;
                                break;
                            case PP.PICNAMEMODE.抓拍员:
                                ans += PP.gUser.username;
                                break;
                            case PP.PICNAMEMODE.部门代码:
                                ans += m_BMBH;
                                break;
                            case PP.PICNAMEMODE.设备编码:
                                ans += m_deviceID;
                                break;
                            default:
                                break;

                        }
                    }

                }
            }
            catch
            {
                ans = "";
            }
            return ans;
        }
        public bool SaveJKRecord()
        {
            bool ans = false;
            try
            {
                if ((m_FileName1 != "") && (m_FileName2 != "") && (m_FileName3 != ""))
                {
                    RecordParam record = new RecordParam();
                    record.SnapCount = m_SnapCount;
                    record.picJionMode = "0";
                    record.recordType = "12";
                    record.Company = "JARI";
                    record.captureDevice = "9";
                    record.deviceID = m_deviceID;
                    record.captureUser = PP.gUser.username;
                    record.WFXWDM = m_WFXWDM;
                    record.GBDM = m_GBDM;
                    record.BMBH = m_BMBH;
                    record.roadid = m_RoadID;
                    record.roadname = m_RoadName;
                    record.directionID = "1";
                    record.CD = "1";
                    record.JGSJ = m_WFSJ.ToString("yyyyMMddHHmmssfff");
                    record.RedLightBeginTime = "";
                    record.RedLightDuration = "0";
                    record.plateType = m_ManuelHPZL;//借用platetype传输ManuelCarType
                    record.ManuelCarType = m_ManuelHPZL;
                    record.plateColor = "";
                    record.HPHM = m_HPHM;
                    record.bodyColor = "0";
                    record.speedLimit = "0";
                    record.speed = "0";

                    record.PIC1 = m_FileName1;
                    record.PIC2 = m_FileName2;
                    record.PIC3 = m_FileName3;
                    record.PIC4 = "";
                    record.PICZoom = "";
                    record.PICPlate = "";

                    record.Save(PP.gJKRecordPath);

                    
                    return true;
                }
            }
            catch
            {
                ans = false;
            }
            return ans;
        }

    }
}
